(function(w, undefined){
	w.undefined = undefined;
	var doc = w.document;

	/*
	 * 根据标志获取父节点
	 * .node 类名
	 * #node_id 节点id
	 * nodeName 默认节点名
	 */
	var $ = function(id) {
		if (typeof(id) == "string") {
			return $q(id);
		} else {
			return id;
		}
	};

	var $q = function (id) {
		if (doc.querySelectorAll)	{
			$q = function (id) {
				if (id.indexOf("#") != -1){
					return doc.querySelector(id)
				}else{
					return doc.querySelectorAll(id);
				}
			}
		}else{
			$q = function (id) {
				var start  = id.charAt(0);
				switch(start){
					case ".":
						return $class(id.substring(1));
						break;
					case "#":
						return $id(id.substring(1));
						break;
					default:
						return $tag(id);
				}
			}
		}

		return $q(id);
	};
	
	var $id = function (id){
		if (doc.getElementById) {
			return document.getElementById(id);
		} else if (doc.all) {
			return doc.all[id];
		}
	};
	var $tag = function (tagName){
		tagName = tagName || "*";
		return doc.getElementsByTagName(tagName.toUpperCase());
	};
	var $class = function(className, tagName){
		if (doc.getElementsByClassName){
			return doc.getElementsByClassName(className);
		}else{
			tagName = tagName || "*";
			
			var rslt, dom;
			var list = doc.getElementsByTagName(tagName.toUpperCase());
			var l = list.length;
			
			rslt = [];
			for (var i = 0; i < l; i++){
				dom = list[i];
				if (dom.className == className){
					rslt.push(dom);
				}
			}
			return rslt;
		}
	};
	//创建dom
	var $e = function(tagName, className, value){
		var temp = doc.createElement(tagName);
		value = value || "";
		className = className || "";
		temp.className = className;
		
		if (tagName.toLowerCase() == "input"){
			temp.value = value;
		}else{
			temp.innerHTML = value;
		}
		
		return temp;
	};
	
	//获取style
	var $s = function(obj){
		obj = $(obj);
		return obj.currentStyle ? obj.currentStyle : getComputedStyle(obj);
	}
	
	/*
	 * 塞入对象
	 */
	var $$ = w.moto =  {
		$: $,
		$c: $class,
		$s:$s,
		$e:$e
	};
	
	/*
	 * 客户端
	 */
	$$.client = (function() {
		//呈现引擎 
		var engine = {
			name: '', //引擎名字ie Gecko Webkit KHTML Opera
			version: '' //版本号
		};
		//浏览器
		var browser = {
			name: '',
			version: ''
		};
		//平台、设备和操作系统
		var system = {
			system: '', //操作系统 win mac xll
			device: '' //设备 iphone android ipod ipad ios nokiaN winMobile
		};
		var ua = navigator.userAgent;
		
		//检测浏览器
		if (window.opera) {
			engine.name = 'opera';
			engine.version = window.opera.version();
		} else if (/AppleWebKit\/(\S+)/.test(ua)) {
			engine.version = RegExp["$1"];
			engine.name = 'webkit';
			var webkit = parseFloat(engine.version);
			//确定是chrome还是safari
			if (/Chrome\/(\S+)/.test(ua)) {
				browser.name = 'chrome';
				browser.version = RegExp["$1"];
			}else if( /Version\/(\S+)/.test(ua)){
				browser.version = RegExp["$1"];
				browser.name = 'safari';
			}else{
				var safariVersion = 1;
				if (webkit < 100){
					safariVersion = 1;
				}else if (webkit < 312){
					safariVersion = 1.2;
				}else if (webkit < 412){
					safariVersion = 1.3;
				}else{
					safariVersion = 2;
				}
				browser.name = 'safari';
				browser.version = safariVersion;
			}
		}else if(/KHTML\/(\S+)/.test(ua) || /Kongqueror\/([^;]+)/.test(ua)){
			engine.version = browser.version = RegExp["$1"];
			engine.name = 'khtml';
			browser.name = 'Kong';
		}else if(/rv:([^\)]+)\) Gecko\/d{8}/.test(ua)){
			engine.version = RegExp["$1"];
			engine.name = 'gecko';
			
			//确定不是firefox
			if (/Firefox\/(\S+)/.test(ua)){
				browser.version = RegExp["$1"];
				engine.name = 'firefox';
			}
		}else if(/MSIE([^;]+)/.test(ua)){
			engine.name = 'ie';
			engine.version = browser.version = RegExp["$1"];
			browser.name = 'ie';
		}
		
		//检测设备 iPod iPad
		if (navigator.userAgent.match(/(iPhone|Android|ios|iOS|Backerry|WebOS|Symbian|Windows Phone|Phone)/i)) { 
			system.device = 'phone';
		}else if (navigator.userAgent.match(/(iPod|iPad)/i)){
			system.device = 'pad';
		}else{
			system.device = 'pc';
		}

		if (ua.indexOf('Android') > -1 || ua.indexOf('Linux') > -1) {//安卓手机
			system.name = "android";
		} else if (ua.indexOf('iPhone') > -1) {
			system.name = "ios";
		} else if (ua.indexOf('Windows Phone') > -1) {//winphone手机
			system.name = "windows phone";
		}else{
			system.name = "unknow";
		}

		var client = {engine:engine, browser:browser, system:system};
		if (typeof w.BaseClient == "function"){
			w.BaseClient(client);
		}
		return client;
	})();


	/*
	 * 日期格式化
	 * moto.formatDate(date, "yyyy-mm-dd hh:mm:ss");
	 */
	//获取今天明天后天 昨天 前天
	$$.lastDays = (function () {
		function getDate(dDays) {
			var d = new Date();
			d.setDate(d.getDate() + dDays);
			return new Date(d);
		}
		return [
			{
				d: getDate(-2),
				name: "前天"
			},
			{
				d: getDate(-1),
				name: "昨天"
			},
			{
				d: getDate(0),
				name: "今天"
			},
			{
				d: getDate(1),
				name: "明天"
			},
			{
				d: getDate(2),
				name: "后天"
			}
		];
	})();
	$$.cDayNames = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	$$.formatDate = function (date, fmt, c) {
		var o = {
			"M+": date.getMonth() + 1, //月份
			"d+": date.getDate(), //日
			"h+": date.getHours(), //小时
			"m+": date.getMinutes(), //分
			"s+": date.getSeconds(), //秒
			"q+": Math.floor((date.getMonth() + 3) / 3), //季度
			"S": date.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));

		if (c && c == "chi"){
			var lastDays = $$.lastDays;
			var d;
			for (var i = 0, l = lastDays.length; i < l; i++) {
				d = lastDays[i].d;
				if (d.getFullYear() == date.getFullYear() && d.getMonth() == date.getMonth() && d.getDate() == date.getDate()){
					fmt = lastDays[i].name + fmt.substr(10);
					break;
				}
			}
		}
		return fmt;
	};
	$$.cDay = function(date){
		return $$.cDayNames[date.getDay()];
	};
	
	/*
	 * 获取事件的信息
	 * x，y坐标
	 * 相对于页面
	 * 
	 * clientX, clientY 相对于窗口
	 * 
	 * targetX, targetY 相对于
	 * mouse是event
	 * 
	 * sign 获取事件侦听标志
	 * 类 .class
	 * id #id
	 * 默认节点名为button
	 * 
	 */
	$$.getEvent = function(e, sign) {
		e = e || window.event;

		//相对于文档
		e.pageX = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
		e.pageY = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
		
		//target事件源
		e.target = e.target || e.srcElement;
		
		//currentTarget事件侦听
		e.currentTarget = e.currentTarget || $$.getParentNode(e.target, sign || "button");
		
		return e;
	};
	
	/*
	 * 根据标志获取父节点
	 * .node 类名
	 * #node_id 节点id
	 * nodeName 默认节点名
	 */
	$$.getParentNode = function (tgr, sign){
		if (!$$.checkIsDom(tgr)){
			return;
		}
		
		var attr = "", tagName;
		sign = sign.toLowerCase();
		tagName = tgr.tagName.toLowerCase();

		switch (sign.charAt(0)){
			case "." :
				attr = "class";
				sign = sign.substring(1);
				break;
			case "#" :
				attr = "id";
				sign = sign.substring(1);
				break;
			default:
				attr = "tagName";
		};
		
		if (attr == "tagName"){
			while(tagName != "html" && tagName != "body"){
				if (tagName == sign){
					return tgr;
					break;
				}
				
				tgr = tgr.parentNode;
				tagName = tgr.tagName.toLowerCase();
			}
		}else{
			var temp = tgr.getAttribute(attr);
			while(tagName != "html" && tagName != "body"){
				if (temp && temp.indexOf(sign) !== -1){
					return tgr;
					break;
				}
				
				tgr = tgr.parentNode;
				tagName = tgr.tagName.toLowerCase();
				temp = tgr.getAttribute(attr);
			}
		}
		
		return;
	};
	
	/*
	 * 如何对象为数组，就会为每个成员进行绑定
	 * event 为添加事件模型 click blur load
	 * eventModel : true ：捕获事件  false:冒泡事件  默认 false
	 */
	$$.bind = function(target, eventName, func, eventModel) {
		target = $(target);
		
		//判定是否为数组
		if ($$.checkIsDom(target)){
			doBind(target, eventName, func, eventModel);
		}else if (target && target.length){
			//如果为数组
	 		var l = target.length;
	 		for (var i = 0; i < l; i ++){
				$$.bind(target[i], eventName, func, eventModel);
	 		}
	 	}
		
		function doBind(target, eventName, func, eventModel){
			eventModel = (typeof(eventModel) == "boolean") ? eventModel : false;
			if (target.attachEvent) {
				target.attachEvent("on" + eventName, func);
			} else {
				target.addEventListener(eventName, func, eventModel);
			}
		}
	};
	$$.remove = function(target, eventName, func, eventModel) {
		if ($$.checkIsDom(target)){
			doRemove(target, eventName, func, eventModel);
		}else if (target && target.length){
			//如果为数组
	 		var l = el.length;
	 		for (var i = 0; i < l; i ++){
	 			doRemove(el[i], eventName, func, eventModel);
	 		}
	 	}
		
		function doRemove(target, eventName, func, eventModel){
			target = $(target);
			eventModel = (typeof(eventModel) == "boolean") ? eventModel : false;
			if (target.detachEvent) {
				target.detachEvent("on" + eventName, func);
			} else {
				target.removeEventListener(eventName, func, eventModel);
			}
		}
	};


	/*
	 * object对象
	 * {pageWidth:1366, pageHeight:768};
	 * pageWidth：页面宽度
	 * pageHeight：页面高度 不计算滚动条的高度
	 */
	$$.getPageSize = function(win) {
		win = win || w || window;
		if (win.document.compatMode == "CSS1Compat") {
			return {
				pageWidth: win.document.documentElement.clientWidth,
				pageHeight: win.document.documentElement.clientHeight
			};
		}else if (typeof win.innerWidth == "number") {
			return {
				pageWidth: win.innerWidth,
				pageHeight: win.innerHeight
			};
		} else {
			return {
				pageWidth: win.document.body.clientWidth,
				pageHeight: win.document.body.clientHeight
			};
		}
	};
	
	/*
	 * 检测是否为微信
	 */
	$$.checkIsWeiXin = (function() {
	    var ua = w.navigator.userAgent.toLowerCase();
	    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
	        return true;
	    } else {
	        return false;
	    }
	})();
	
	/*
	 * 获取url后面的拼接参数
	 * www.baidu.com?a=1&b=2&c=3
	 * 返回对象 {a:1, b:2, c:3};
	 */
	$$.urlArgs = (function() {
		var locationSearch = window.location.search.substr(1);
		var l = locationSearch.length;
		if (l > 0) {
			var items = locationSearch.split("&");
			var item, name, i, value, args = {};
			l = items.length;
			for (i = 0; i < l; i++) {
				item = items[i].split("=");
				name = item[0];
				value = item[1];
				if (name.length) {
                    try {
                        args[name] = decodeURIComponent(value);
                    } catch (e) {
                        console.error('decodeURIComponent出现异常：', name, value, e);
                    }
				}
			}
			return args;
		} else {
			return {};
		}
	})();

	/*删除url后面的指导参数
	 * demo: www.baidu.com?a=1&b=2&c=3
	 *       moto.deleteUrlArgs(['a', 'b']);
	 * return: http://www.baidu.com?c=3
	 */
	$$.deleteUrlArgs = function(nameArr){
		var host = "http://" + window.location.host;
		var path = window.location.pathname;
		var locationSearch = window.location.search.substr(1);
		var l = locationSearch.length;
		if(l > 0){
			var items = locationSearch.split("&");
			var item, _key, _value, args = '', temp;
			l = items.length;
			for(var i = 0; i < l; i++){
				item = items[i].split("=");
				_key = item[0];
				_value = item[1];
				if(_key.length){
					for(var j = 0, len = nameArr.length; j < len; j++){
						temp = 0;
						if(_key == nameArr[j]){
							temp = 1;
							break;
						}
					}
					if(temp == 1) continue;
					if(args.length == 0){
						args += "?" + _key + "=" + _value;
					}else{
						args += "&" + _key + "=" + _value;
					}
				}
			}
			return host + path + args;
		}else{
			return host + path;
		}
	};

	$$.addUrlAgrs = function (url, name, value){
		if (url.indexOf('?') != -1){
			return url + '&' + name + '=' + value;
		}else{
			return url + '?' + name + '=' + value;
		}
	};
	
	/*
	 * 增加类 判定类 移除类
	 */
	 $$.hasClass = function(obj, cls) {
        return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    }

    $$.addClass = function(obj, cls) {
        if (!this.hasClass(obj, cls)) {
        	obj.className += " " + cls;
        }
        return obj.className;
    }

    $$.removeClass = function(obj, cls) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
		var reslt = reg.exec(obj.className);
		if (reslt) {
			obj.className = obj.className.replace(reg, reslt[2] || "");
		}
		return obj.className;
	};
	
	$$.imgloader = function(src, callback, arg){
		var tempImg = new Image();
		tempImg.src = src;

		if (tempImg.complete) {
			if (typeof callback == "function"){
				callback(src, arg);
			}
		} else {
			tempImg.onload = function() {
				if (typeof callback == "function"){
					callback(src, arg);
				}
			};
		}
	}

	//tsrc
	$$.renderImg = function (imgs) {
		if (imgs.length){
			var img, src;
			for (var i = 0, l = imgs.length; i < l; i++) {
				img = imgs[i];
				src = img.getAttribute("tsrc");
				if (src){
					$$.imgloader(src, render, img);
					img.removeAttribute("tsrc");
				}
			}
		}else{
			if (imgs.nodeName && imgs.nodeName.toLocaleLowerCase() == "img"){
				var src = imgs.getAttribute("tsrc");
				if (src){
					$$.imgloader(src, render, imgs);
					imgs.removeAttribute("tsrc");
				}
			}
		}
		function render(src, img) {
			img.src = src;
		}
	}

	
	/*
	 * author：画画
	 * 解决问题 映射dom节点的属性或值
	 * @dom dom节点
	 * @datas 数据 数组或者{}
	 * @auto 是否自动填充 布尔值
	 * 
	 * repeater属性标志是否重复填充
	 * ${@name||defaultValue}或者${@name} 书写格式
	 *
	 * 备注：${@repeaterSequence}为重复填充的序列 1开始  
	 * ${@repeaterSequenceChar} A/B/C/D
	 * 大小写敏感
	 *
	 * ${@repeaterFirst} 首 first
	 * ${@repeaterLast} 尾 last
	 *
	 *
	 * 
	 * **********************************************************
	 * 使用说明  
	 * data = {name:pccold};
	 * <div id="test" repeater="true">
	 * 		<p>${@name||画画}</p>
	 * </div>
	 * moto.dataMapHtml("test", data, true);
	 *
	 * nullText 若数据为空自动填充的内容
	 *
	 * **********************************************************
	 */
	
	$$.dataMapHtml = function(dom, datas, auto, nullText){
		var obj, result, template;
		dom = $(dom);
		result = "";
		
		template = dom.template;//读取模板
		if (!template){
			template = dom.template = dom.innerHTML;
		}
		
		//测试数据类型 数组
		if (datas instanceof Array){
			//重复渲染
			if (dom.getAttribute("repeater")){
				var l = datas.length;
				for (var i = 0; i < l; i++){
					obj = datas[i];
					obj.repeaterSequence = (i + 1);
					obj.repeaterSequenceChar = String.fromCharCode(i + 65);

					if (i == 0){
						datas[0].repeaterFirst = "first";
					}

					if (l == i + 1){
						datas[l - 1].repeaterLast = "last";
					}
					
					result += render(template, obj);
				}



			}else if (datas.length > 0){
				obj = datas[0];
				result = render(template, obj);
			}
		}else{
			result = render(template, datas);
		}

		result = result || nullText || "";
		if (auto){
			dom.innerHTML = result;
			dom.style.visibility = "visible";
		}
		return result;
		
		
		//渲染html
		function render(html, data){
			var re, v;
			
			/*
			 * 遍历数据属性
			 * \$\{@attr}|\$\{@attr\|\|[^\$\{@]*}
			 * 匹配${@attr||defaultValue}
			 */
			for(var attr in data){
				v = data[attr];
				if (v !== undefined && v !== null && v !== NaN){
					re = new RegExp("\\$\\{@" + attr + "}|\\$\\{@" + attr + "\\|\\|[^\\$\\{@]*}", "g");
					html = html.replace(re, v);
				}
			}
			
			/*
			 * 去除未匹配的值
			 * 匹配任意 \$\{@[^\$\{@]*}
			 */
			re = new RegExp("\\$\\{@[^\\$\\{@]*}", "g");
			var arr = html.match(re);
			if (arr){
				var l = arr.length, str, start;
				for(var i = 0; i < l; i ++){
					str = arr[i];
					start = str.indexOf("||") + 2;
					
					if (start > 3){
						html = html.replace(str, str.substring(start, str.length - 1));
					}else{
						html = html.replace(str, "");
					}
				}
			}
			return html;
		}
	}
	
	/*
	 * mask
	 * 弹出的
	 * 可设置zIndex
	 */
	$$.masker = {
		dom: $e("div", "mask-container", ""),
		mask:function(){
			var back = $$.masker.dom;
			if (!back.parentNode){
				doc.body.appendChild(back);
			}
			if ($s(back).display == "none"){
				back.style.display = "block";
			}else{
				jQuery(back).animate({
					opacity: 0.5
				}, 200, function () {
					back.style.display = "none";
				});
			}
		},
		hideMask:function(){
			var back = $$.masker.dom;
			if (!back.parentNode){
				doc.body.appendChild(back);
			}
			jQuery(back).animate({
				opacity: 0.5
			}, 200, function () {
				back.style.display = "none";
			});
		},
		showMask:function(){
			var back = $$.masker.dom;
			back.style.height = Math.max(document.documentElement.scrollHeight, $$.getPageSize().pageHeight) + "px";
			if (!back.parentNode && back != back.parentNode){
				doc.body.appendChild(back);
			}
			$$.masker.dom.style.display = "block";
		}
	}
	
	/*
	 * element 遮罩的父级元素
	 * 加载中描述
	 */
	$$.loadingDataAnimal = function(element, text, showBack){

		var dom = $$.loadingContainer;
		if (!dom){
			var s = "<div class='content'>";
			s += "<img src='/static/img/common/loading.gif' class='load-icon-con td' /><SPAN class='loading-info'></SPAN>";
			s += "</div><div class='back'></div>";
			dom =　$$.loadingContainer = $e("div", "loading-container", s);

			$$.registerResize(dom); //自适应尺寸
		}
		element = element || doc.body;
		text = text || "load...";

		dom.style.visibility = "hidden";
		dom.style.display = "block";
		
		if (element == doc.body){
			dom.ifResize = true;
			dom.style.position = "fixed";
			dom.style.height = moto.getPageSize().pageHeight + "px";
			dom.style.width = moto.getPageSize().pageWidth + "px";
			dom.style.top = "0px";
			dom.style.left = "0px";
		}else{
			dom.ifResize = false;
			dom.style.top = element.offsetTop + "px";
			dom.style.left = element.offsetLeft + "px";
			dom.style.height = element.offsetHeight + "px";
			dom.style.width = element.offsetWidth + "px";
			dom.style.position = "absolute";
		}

		if (!showBack){
			jQuery(dom).css("position", "static");
			jQuery(dom).css("height", "0px");
			jQuery(dom).find(".back").addClass("none");
		}else{
			jQuery(dom).find(".back").removeClass("none");
		}

		element.appendChild(dom);
		var content = dom.children[0].children[1];
		content.innerHTML = text;
		content.parentNode.style.marginTop = content.parentNode.offsetHeight / -2 + "px";
		content.parentNode.style.marginLeft = content.parentNode.offsetWidth / -2 + "px";
		dom.style.visibility = "visible";
	};
	$$.removeLoadingAnimal = function(){
		var dom = $$.loadingContainer;
		if (dom && dom.parentNode){
			dom.ifResize = false;
			dom.style.display = "none";
			dom.parentNode.removeChild(dom);
		}
	};
	
	/*
	 * console
	 */
	$$.console = function(message) {
		var div = $$.messageDom = $$.messageDom || $$.$e("div", "log-message", "");
		div.innerHTML = message;
		if (!document.body){
			setTimeout(function(){
				$$.console(message);
			}, 100);
		}else{
			document.body.appendChild(div);
		}
	};

	/*
	 * 输出消息
	 * motoConfirm用于存储回调函数
	 * confirmControl响应事件
	 */
	var motoMessage = {
		dom: null,
		message: null,
		ok: null,
		cancel: null,
		close: null
	};
	w.messageControl = function(element, data){
		//隐藏
		$$.getParentNode(element, ".confirm-message-container").ifResize = false;

		$$.masker.hideMask();
		jQuery(motoMessage.dom).animate({
			opacity: 0,
			width: 0,
			height: 0,
			marginLeft: 0,
			marginTop: 0
		}, 100, function () {
			motoMessage.dom.parentNode.removeChild(motoMessage.dom);
			var func = motoMessage[data];
			if (typeof func == "function"){
				func(element, data);
			}
		});
	};
	$$.message = function(titile, message, okFunc, cancelFunc, closeFunc){
		var div = motoMessage.dom || (motoMessage.dom = initconfirDom());

		div.children[0].innerHTML = titile;
		div.children[1].innerHTML = message;
		motoMessage.ok = okFunc;
		motoMessage.cancel = cancelFunc;
		motoMessage.close = closeFunc;

		if (cancelFunc === undefined){
			div.children[2].className = "btn-con just-ok";
		}else{
			div.children[2].className = "btn-con both";
		}
		doc.body.appendChild(div);

		var page = $$.getPageSize();
		var wi = Math.floor(380);
		var he = Math.floor(180);

		div.style.display = "block";
		div.style.zoom = "1";

		$$.masker.showMask();
		jQuery(motoMessage.dom).animate({
			opacity: 1,
			width: wi + "px",
			height: he + "px",
			marginLeft: (wi / -2) + "px",
			marginTop: (he * 2 / -3) + "px"
		}, 100, function () {
			div.ifResize = true;
		});

		function initconfirDom(){
			var s = "<h1 class='message-title'>" + "</h1>";
			s += "<p class='message'></p>";
			s += "<div><span onclick='messageControl(this, \"ok\")' event-data='ok' event-func='messageControl' class='ok-btn message-btn' hover='hover-ok'>确定</span>";
			s += "<span  onclick='messageControl(this, \"cancel\")' class='cancel-btn message-btn' hover='hover-cancel'>取消</span></div>";

			var div = $$.registerResize($$.$e("div", "confirm-message-container", s)); //自适应尺寸
			div.resetSize = function (dom, pageSize) {
				var wi = Math.floor(380);
				var he = Math.floor(180);
				dom.style.display = "block";
				dom.style.marginTop = (he * 2 / -3) + "px";
				dom.style.marginLeft = (wi / -2) + "px";
				dom.style.width = wi + "px";
				dom.style.height = he + "px";
				dom.style.zoom = 1;
			};
			return div;
		}
	};

	/**
	 * 漂浮提示信息（逐渐消失）
	 * */
	$$.floatMessage = function (info){
		var div = $$.$e("div", "float-message", info);
		doc.body.appendChild(div);
		jQuery(".float-message").animate({top : "5%", opacity : 0}, 2000,function () {
            div.remove();
        });
	};

	/**
	 *  字符串'> <'转为字符实体
	 */
	$$.changeChars = function(str){
		var temp = str;
		temp = temp.replace('<', '&#60;');
		temp = temp.replace('>', '&#62;');
		return temp;
	};

	/*
	 * 检查是否为
	 * HTMLElement对象
	 */
	$$.checkIsDom = function(obj){
		//排除window document document.documentElement特殊对象
		if (obj == doc || obj == window){
			return true;
		}
		return ( typeof HTMLElement === 'function' ) ? (obj instanceof HTMLElement) : (obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string');
	}
	
	//返回空的object对象防止报错
	$$.localStorage = (function(w){
		if (w.localStorage){
			return w.localStorage;
		}else{
			return {};
		}
	})(w);
	$$.removeLocalStorage = function (key) {
		if (w.localStorage){
			$$.localStorage.removeItem(key);
			return true;
		}else{
			return false;
		}
	};
	$$.setLocalStorage = function(key, value){
		if (w.localStorage){
			if (typeof value != "object"){
				$$.localStorage.setItem(key, value);
			}else{
				$$.localStorage.setItem(key, JSON.stringify(value));
			}
			return true;
		}else{
			return false;
		}
	};
	$$.getLocalStorage = function(key){
		if (w.localStorage){
			return $$.localStorage.getItem(key);
		}
	};

	/*
	 *
	 */
	$$.addCSS = function(cssText){
		var style = document.createElement('style');  //创建一个style元素
		var head = document.head || document.getElementsByTagName('head')[0]; //获取head元素
		style.type = 'text/css'; //这里必须显示设置style元素的type属性为text/css，否则在ie中不起作用

		if(style.styleSheet){ //IE
			var func = function(){
				try{ //防止IE中stylesheet数量超过限制而发生错误
					style.styleSheet.cssText = cssText;
				}catch(e){

				}
			}

			//如果当前styleSheet还不能用，则放到异步中则行
			if(style.styleSheet.disabled){
				setTimeout(func,10);
			}else{
				func();
			}

		}else{

			//w3c浏览器中只要创建文本节点插入到style元素中就行了
			var textNode = document.createTextNode(cssText);
			style.appendChild(textNode);
		}
		head.appendChild(style); //把创建的style元素插入到head中
	};

	$$.getTimeFormat = function(t, seprator) {
		var s = "";
		//t = t % 3600;
		s += getS(Math.floor(t / 60));
		s += (seprator || ":") + getS(Math.floor(t % 60));
		return s;

		function getS(v) {
			return (v > 9) ? (v + "") : ("0" + v);
		}
	}

	$$.getCookie = function(key){
		if (document.cookie.length>0){
			var start = document.cookie.indexOf(key + "=");
			var end = null;
			if (start!=-1)
			{
				start = start + key.length+1;
				end = document.cookie.indexOf(";", start);
				if (end == -1){
					end = document.cookie.length;
				}
				return unescape(document.cookie.substring(start, end));
			}
		}
		return ""
	};

	$$.setCookie = function(key, value, expiredays, path){
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		path = path || "/";
        var cooikeKeyValue = key + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()) + ";path=" + path;
		var hostname = window.location.hostname;
		if(hostname == "pc.costoon.com") {
            document.cookie = cooikeKeyValue + ";domain=www.costoon.com";
		} else if(hostname == "www.costoon.com"){
            document.cookie = cooikeKeyValue + ";domain=pc.costoon.com";
		}
		document.cookie = cooikeKeyValue;
	};

	$$.getRandomStr = function(len) {
		len = len || 32;
		var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';/****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
		var maxPos = $chars.length;
		var pwd = '';
		for (var i = 0; i < len; i ++) {
			pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
		}
		return pwd;
	};

	//resize时候更新尺寸 resetSize
	var resizeArray = new Array();
	$$.registerResize = function (dom) {
		resizeArray.push(dom);
		return dom;
	};
	$$.registerResize($$.masker.dom);
	$$.resetComponentsSize = function () {
		var pageSize = $$.getPageSize();
		var dom, func;
		for (var i = 0, l = resizeArray.length; i < l; i++){
			dom = resizeArray[i];
			if (dom.ifResize){
				func = dom.resetSize;
				if (func && typeof func == "function"){
					func(dom, pageSize);
				}else{
					dom.style.width = pageSize.pageWidth + "px";
					dom.style.height = pageSize.pageHeight + "px";
				}
			}
		}
	};
	$$.bind(w, "resize", $$.resetComponentsSize);

	/*
	 * ajax 基于jquery
	 *
	 */
	$$.ajax = function (config) {
		var func = config.success;
		var error = config.error;
		if (!config){
			return;
		}
		if (config.mask){
			$$.loadingDataAnimal(config.mask.dom || doc.body, config.mask.info || "", config.mask.showBack);
		}

		//增加channel 和 device
		// var channel = moto.urlArgs.channel;
		// if (channel){
		// 	config.data.channel = channel;
		// }
		// config.data.device = moto.client.device;

		config.contentType = config.contentType || 'application/x-www-form-urlencoded; charset=UTF-8';

		config.error =  function(res){
			if (config.mask){
				$$.removeLoadingAnimal();
			}
			if (typeof error == "function"){
				func(res);
			}
			$$.ctrlAjaxError(res);
		};
		config.success = function(res){
			
			if (config.mask){
				$$.removeLoadingAnimal();
			}
			if (typeof func == "function"){
				func(res);
			}
		};
		jQuery.ajax(config);
	};

	$$.ctrlAjaxError = function (res) {
		if (res.statusText == "No Transport"){
			moto.message("提示", "浏览器无法请求跨域数据，请用更高级chrom浏览器。", function(){
				location.href = "/page/user/login.html";
			}, 1);
		}
		if (res.responseText == "E00049"){
            moto.setCookie("token", "", -1);
            moto.setCookie("userid", "", -1);
            moto.setCookie("phone", "", -1);
            moto.setCookie("nickname", "", -1);
            moto.setCookie("avatar", "", -1);
            moto.setCookie("accountType", "", -1);
			moto.message("提示", "登录已失效，是否去登录？", function(){
				location.href = "/page/user/login.html";
			}, function(){}, 1);
		}
	};

	$$.getDataByAttr = function(datas, attr, value, ifRandom) {
		var l = datas.length;
		var data, reslt = [];
		for (var i = 0; i < l; i++){
			data = datas[i];
			if (data[attr] == value){
				reslt.push(data);
			}
		}

		if (ifRandom){
			return moto.getRandomDatas(reslt);
		}else{
			return reslt;
		}
	};

	$$.getRandomDatas = function(datas) {
		var kindDatas = [];
		var l = datas.length;
		var data, mid, lmid = -1, i, last;

		//分类
		for (i = 0; i < l; i++){
			data = datas[i];
			mid = data.material_id;

			//根据材料id 依赖于材料题连续的特性
			if (mid){
				if (last && lmid == mid){
					last.num ++;
				}else{
					last = {
						start: i,
						num: 1
					};
					kindDatas.push(last);
				}
			}else{
				last = {
					start: i,
					num: 1
				};
				kindDatas.push(last);
			}
			lmid = mid;
		}


		//打乱分好类的数组
		var randomKindDatas = [];
		i = 0;
		l = kindDatas.length;
		while(i < l){
			randomKindDatas.push(kindDatas.splice(Math.floor(Math.random() * (l - i)), 1)[0]);
			i ++;
		}

		//读取分类数据 再读取数据
		var rslt = [];
		l = randomKindDatas.length;
		for (i = 0; i < l; i++){
			data = randomKindDatas[i];
			for (var j = 0; j < data.num; j++){
				rslt.push(datas[data.start + j]);
			}
		}

		return rslt;
	};

	$$.loadJs = function (url, sign, callback) {
		$$.loadFile(url, "js");

		//标志回调
		checkLoadComplete();
		
		function checkLoadComplete() {
			if (window[sign]){
				if (typeof callback == "function"){
					callback();
				}
			}else{
				setTimeout(arguments.callee, 10);
			}
		}
	};

	$$.loadFile = function(path, type, sync) {
		type = type || (path.indexOf(".css") > -1 ? "css" : "js");

		if (!sync){
			var head = document.getElementsByTagName('head')[0];
			var node;

			if (type == "css"){
				node = document.createElement('link');
				node.href = path;
				node.rel = 'stylesheet';
				node.type = 'text/css';
			}else{
				node = document.createElement('script');
				node.src = path;
				node.type = 'text/javascript';
			}
			head.appendChild(node);
		}else{
			var str;
			if (type == "css"){
				str = '<link type="text/css" rel="stylesheet" href="' + path + '" />';
			}else{
				str = '<script type="text/javascript" src="' + path + '" ></script>';
			}
			document.write(str);
		}
	};

})(window === undefined ? this : window);
